package com.news.service;

import com.news.dao.UserDao;
import com.news.dao.UserDaoImpl;
import com.news.entity.User;
import com.news.util.Page;

public class UserServiceImpl implements UserService {

	private UserDao userDao = new UserDaoImpl();
	
	@Override
	public int saveUser(User user) {
		return userDao.insertUser(user);
	}

	@Override
	public int editUser(User user) {
		return userDao.updateUser(user);
	}

	@Override
	public int removeUser(int id) {
		return userDao.deleteUser(id);
	}

	@Override
	public int removeUserBatch(String[] ids) {
//		return userDao.deleteUserBatch(ids);
		return userDao.deleteUserBatch2(ids);
	}

	@Override
	public User getUser(int id) {
		return userDao.selectOneUser(id);
	}

	@Override
	public Page listUser(int pageNum, int pageSize, String acct) {
		//创建分页组件对象
		Page page = new Page();
		//设置当前页数
		page.setPageNum(pageNum);
		//设置每页条数
		if(pageSize!=0){
			page.setPageSize(pageSize);
		}
		//设置总记录数
		page.setTotal(userDao.selectCount(acct));
		//设置当前页数据
		page.setData(userDao.selectUser(page.getOffset(), page.getPageSize(), acct));
		return page;
	}

	@Override
	public User login(String acct, String pwd) {
		return userDao.login(acct, pwd);
	}

}
